package com.handy.socket;

import java.nio.channels.SocketChannel;
import java.nio.ByteBuffer;
import java.io.IOException;

import org.apache.log4j.Logger;

/**
 * 回应器
 * 用于向客户端发送数据
 * @author rocken.zeng@gmail.com
 * @version 1.0
 */

public class Response {
    private SocketChannel sc;

    public Response(SocketChannel sc) {
        this.sc = sc;
    }

    /**
     * 向客户端写数据
     * @param data byte[]　待回应数据
     */
    public void send(byte[] data){
        ByteBuffer buffer = ByteBuffer.allocate(data.length);
        buffer.put(data, 0, data.length);
        buffer.flip();
        try {
			sc.write(buffer);
		} catch (IOException e) {
			log.error(e.getMessage());
		}
    }
    
    private static Logger log = Logger.getLogger(Response.class);
}
